home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
-
- use DBI;
- use CGI qw/:standard :escape :unescape/;
- use LWP::UserAgent;
-
- $mailprog = '/bin/sendmail';
-
- $register_url = 'http://www.3d3.com/encrypt/regdb_register.cgi';
-
- $email_alert = 'tech@3d3.com'; # email in case of fatal error
- $email_contact = 'support@3d3.com'; # email address to give to client
- $email_regdb = 'tech@3d3.com'; # email of person who processes registrations
-
- $database = 'regdb';
- $user = 'x3d3';
- $passwd = '4dcubed';
-
- # Start returning a page...
- print "Content-type: text/html\n\n";
-
- @required =(
- 'code',
- 'customername',
- 'customerstreet',
- 'customercity',
- 'customerzip',
- 'customercountry',
- 'customerphone',
- 'customeremail'
- );
-
- my($code) = param('code');
- my($product) = param('product');
- my($version) = param('version');
- my($mversion) = param('mversion');
- my($language) = param('language');
- my($unlocker) = param('unlocker');
- my($customername) = param('customername');
- my($customercompany) = param('customercompany');
- my($customerstreet) = param('customerstreet');
- my($customercity) = param('customercity');
- my($customerstate) = param('customerstate');
- my($customerzip) = param('customerzip');
- my($customercountry) = param('customercountry');
- my($customerphone) = param('customerphone');
- my($customerfax) = param('customerfax');
- my($customeremail) = param('customeremail');
-
- my($coc) = param('coc');
- my($oldcode) = param('oldcode');
-
- if($coc) {
- push(@required, 'oldcode');
- }
-
- # check required fields
- &check_required;
-
- # connect to the database
- $dbh = DBI->connect("DBI:mysql:$database", $user, $passwd);
- if($dbh) {
-
- my($ok) = 1;
-
- # are we checking the old code? ie: is this a distributor-sold upgrade?
-
- if($coc) {
- # yes...
- if(&check_old_code($dbh, $code, $product, $version, $oldcode)) {
- $ok = 1;
- } else {
- $ok = 0;
- }
- }
-
- if($ok) {
- if(&check_code($dbh, $code)) {
- my($sql) = "UPDATE Customer SET";
- $sql .= " CustomerName=" . $dbh->quote($customername) . ",";
- $sql .= " CustomerCompany=" . $dbh->quote($customercompany) . ",";
- $sql .= " CustomerStreet=" . $dbh->quote($customerstreet) . ",";
- $sql .= " CustomerCity=" . $dbh->quote($customercity) . ",";
- $sql .= " CustomerState=" . $dbh->quote($customerstate) . ",";
- $sql .= " CustomerZip=" . $dbh->quote($customerzip) . ",";
- $sql .= " CustomerCountry=" . $dbh->quote($customercountry) . ",";
- $sql .= " CustomerPhone=" . $dbh->quote($customerphone) . ",";
- $sql .= " CustomerFax=" . $dbh->quote($customerfax) . ",";
- $sql .= " CustomerEmail=" . $dbh->quote($customeremail);
- $sql .= " WHERE Code=" . $dbh->quote($code);
- my($sth) = $dbh->prepare($sql);
- if($sth) {
- if($sth->execute) {
- $ok = 1;
- } else {
- &print_html('Error: $sth->execute() Failed', $sth->errstr);
- }
- } else {
- &print_html('Error: $dbh->prepare() Failed', $dbh->errstr);
- }
-
- if($ok) {
- $ok = 0;
- $sql = "UPDATE Reg SET";
- $sql .= " Name=" . $dbh->quote($customername) . ",";
- $sql .= " Email=" . $dbh->quote($customeremail) . ",";
- $sql .= " RequestCust=0";
- $sql .= " WHERE Code=" . $dbh->quote($code);
- my($sth) = $dbh->prepare($sql);
- if($sth) {
- if($sth->execute) {
- $ok = 1;
- } else {
- &print_html('Error: $sth->execute() Failed', $sth->errstr);
- }
- } else {
- &print_html('Error: $dbh->prepare() Failed', $dbh->errstr);
- }
- }
- }
- }
-
- $dbh->disconnect;
-
- if($ok) {
- # It's ok, give the unlock code
- my($url);
- $url = "$register_url";
- $url .= "?code=" . escape($code);
- $url .= "&email=" . escape($customeremail);
- $url .= "&product=" . escape($product);
- $url .= "&version=" . escape($version);
- $url .= "&mversion=" . escape($mversion);
- $url .= "&language=" . escape($language);
- $url .= "&unlocker=" . escape($unlocker);
- $url .= "&bgcolor=" . escape(param('bgcolor'));
- $url .= "&text_color" . escape(param('text_color'));
- $url .= "&link_color" . escape(param('link_color'));
- $url .= "&vlink_color" . escape(param('vlink_color'));
- $url .= "&alink_color" . escape(param('alink_color'));
-
- my($ua) = new LWP::UserAgent;
- my($req) = new HTTP::Request GET => $url;
- my($res) = $ua->request($req);
- if($res->is_success) {
- print $res->content;
- } else {
- &print_html('Fatal Error: Can\'t Redirect To regdb_register.cgi');
- &send_error_report('Can\'t Redirect To regdb_register.cgi');
- }
- }
- } else {
- &print_html('Error: $dbh->connect() Failed', "Unable to connect to database - $dbh->errstr");
- }
-
- sub check_old_code {
- my($dbh, $code, $product, $version, $oldcode) = @_;
- my($ok) = 0;
-
- my($qcode) = $dbh->quote($code);
- my($qoldcode) = $dbh->quote($oldcode);
-
- my($sql) =<<"__EOSQL__";
- SELECT
- RegOld.Code as OldCode, RegOld.ProductID as OldProductID, RegOld.Version as OldVersion,
- RegNew.Code as NewCode, RegNew.ProductID as NewProductID, RegNew.Version as NewVersion,
- RegNew.Upgrade,
- ProdOld.Name as OldName, ProdNew.Name as NewName
- FROM
- Reg as RegOld, Reg as RegNew, Product as ProdOld, Product as ProdNew
- WHERE
- RegOld.ProductID = ProdOld.ProductID AND
- RegNew.ProductID = ProdNew.ProductID AND
- RegOld.Code = $qoldcode AND
- RegNew.Code = $qcode
- __EOSQL__
-
- my($sth) = $dbh->prepare($sql);
- if($sth) {
- if($sth->execute) {
- my($hashref) = $sth->fetchrow_hashref;
-
- if($hashref) {
-
- # At this point we have:
- # Code, Product, Version and Name of old product
- # Code, Product, Version, Name, and Upgrade String of new product.
- # The Upgrade string is in the form "OldProd OldVer to NewProd NewVer".
-
- my($u_oprod, $u_over, $u_nprod, $u_nver) = ($$hashref{'Upgrade'} =~ /^(\w+)\s+(\w+)\s+\Qto\E\s+(\w+)\s+(\w+)/);
-
- if( ($u_oprod eq $$hashref{'OldName'}) && ($u_over eq $$hashref{'OldVersion'}) ) {
- # The old product and version from the upgrade string match the product and version from the
- # old code. Note that as this is meant to deal with distributor-sold codes, we are ok only looking
- # at the first matched product, as there will only ever be one product per code.
-
- # Note that we do not as yet require that the previous product be registered - it must only exist.
-
- # At this point, we should remove the old record, so that it can't be upgraded-from again.
- # However, this would mean that the legitimate owner would not be able to request an unlock code
- # more than once...
-
- $ok = 1;
-
- } else {
- # The old product and version from the upgrade string do not match the product and version from
- # the old code.
- my($htmlbody) = <<"__EOHTML__";
- <p>The Upgrade you are registering is from $$hashref{'Upgrade'}. The product specified by the Code you entered from your
- previous version of ShopFactory is "$$hashref{'OldName'} $$hashref{'OldVersion'}", and thus you cannot register
- this upgrade.</p>
- <p>Please use your browser's back button to return to the previous page, check the code you entered, and try again.</p>
- __EOHTML__
- &print_html('Invalid Previous Code', $htmlbody);
- }
-
- } else {
- my($htmlbody) = <<"__EOHTML__";
- <p>The Code you entered from your previous version of ShopFactory was not found
- in our database. Please use your browser's back button to return to the
- previous page, check your code and try again.</p>
- __EOHTML__
- &print_html('Previous Code Does Not Exist', $htmlbody);
- }
-
- $sth->finish;
- } else {
- &print_html('Error: $sth->execute() Failed', $sth->errstr);
- }
- } else {
- &print_html('Error: $dbh->prepare() Failed', $dbh->errstr);
- }
- return($ok);
- }
-
- sub check_code {
- my($dbh, $code) = @_;
- my($ok) = 0;
- my($exists) = 0;
-
- my($sql) = "SELECT * FROM Customer WHERE Code='$code'";
- my($sth) = $dbh->prepare($sql);
- if($sth) {
- if($sth->execute) {
- if($sth->rows > 0) {
- $exists = 1;
- $ok = 1;
- }
- $sth->finish;
- } else {
- &print_html('Error: $sth->execute() Failed', $sth->errstr);
- }
- } else {
- &print_html('Error: $dbh->prepare() Failed', $dbh->errstr);
- }
-
- if(!$exists) {
- $sql = "INSERT INTO Customer (Code) VALUES ('$code')";
- $sth = $dbh->prepare($sql);
- if($sth) {
- if($sth->execute) {
- $ok = 1;
- } else {
- &print_html('Error: $sth->execute() Failed', $sth->errstr);
- }
- } else {
- &print_html('Error: $dbh->prepare() Failed', $dbh->errstr);
- }
- }
- return($ok);
- }
-
- sub check_required {
-
- if( !(param('code')) || param('code') eq ' ') {
- &print_html("Fatal Error: Code Not Specified", "<p>Your Code has not be passed through correctly.</p>");
- &send_error_report('Code Not Specified');
- exit;
- } else {
- my($missing) = 0;
- foreach $require (@required) {
- if (!(param($require)) || param($require) eq ' ') {
- $missing = 1;
- last;
- }
- }
- if($missing) {
-
- my($bgcolor) = param('bgcolor');
- my($text_color) = param('text_color');
- my($link_color) = param('link_color');
- my($vlink_color) = param('vlink_color');
- my($alink_color) = param('alink_color');
-
- my($htmlbody) =<<"__EOHTML__";
- <center>
- <p><font color="#ff0000">Some required fields have been left blank.</font></p>
- <p>Please enter your details to register:</p>
- <form action="regdb_updatecust.cgi" method="post">
- <input type="hidden" name="bgcolor" value="$bgcolor">
- <input type="hidden" name="text_color" value="$text_color">
- <input type="hidden" name="link_color" value="$link_color">
- <input type="hidden" name="vlink_color" value="$vlink_color">
- <input type="hidden" name="alink_color" value="$alink_color">
- <input type="hidden" name="code" value="$code">
- <input type="hidden" name="product" value="$product">
- <input type="hidden" name="version" value="$version">
- <input type="hidden" name="mversion" value="$mversion">
- <input type="hidden" name="language" value="$language">
- <input type="hidden" name="unlocker" value="$unlocker">
- <table border="1" bgcolor="#ffef90">
- <tr>
- <th align="left">Name</th>
- <td colspan="3"><input type="text" size="40" name="customername" value="$customername"></td>
- </tr>
- <tr>
- <th align="left">Company</th>
- <td colspan="3"><input type="text" size="40" name="customercompany" value="$customercompany"></td>
- </tr>
- <tr>
- <th align="left">Street</th>
- <td colspan="3"><input type="text" size="40" name="customerstreet" value="$customerstreet"></td>
- </tr>
- <tr>
- <th align="left">City</th>
- <td colspan="3"><input type="text" size="40" name="customercity" value="$customercity"></td>
- </tr>
- <tr>
- <th align="left">State</th>
- <td><input type="text" size="20" name="customerstate" value="$customerstate"></td>
- <th align="left">Zip</th>
- <td><input type="text" size="8" name="customerzip" value="$customerzip"></td>
- </tr>
- <tr>
- <th align="left">Country</th>
- <td colspan="3"><input type="text" size="40" name="customercountry" value="$customercountry"></td>
- </tr>
- <tr>
- <th align="left">Phone</th>
- <td colspan="3"><input type="text" size="40" name="customerphone" value="$customerphone"></td>
- </tr>
- <tr>
- <th align="left">Fax</th>
- <td colspan="3"><input type="text" size="40" name="customerfax" value="$customerfax"></td>
- </tr>
- <tr>
- <th align="left">Email</th>
- <td colspan="3"><input type="text" size="40" name="customeremail" value="$customeremail"></td>
- </tr>
- </tr>
- </table>
- __EOHTML__
-
- if($coc == 1) {
- $htmlbody .=<<"__EOHTML__";
- <br>
- <p>The product you are registering is an upgrade. Please enter the Code from your
- previous version of ShopFactory.</p>
- <table border="1" bgcolor="#ffef90">
- <tr>
- <th align="left">Previous Code</th>
- <td colspan="3"><input type="text" size="40" name="oldcode" value="$oldcode"></td>
- </tr>
- </table>
- <input type="hidden" name="coc" value="1">
- __EOHTML__
- }
-
- $htmlbody .=<<"__EOHTML__";
- <br><input type="submit" value="Submit"> <input type="reset" value="Reset"></center>
- </form>
- __EOHTML__
-
- &print_html("Enter Customer Details", $htmlbody);
- exit;
- }
- }
- }
-
- sub send_error_report {
- my($error) = @_;
- my($body);
-
- $body = "$date\n";
- $body .= "Error: $error\n";
-
- $body .= "\n----- Param Info -----\n\n";
-
- my (@names) = param;
- for $name (@names) {
- $body .= "$name = " . param($name) . "\n";
- }
-
- $body .= "\n----- UA Info -----\n\n";
- $body .= "Browser: $ENV{'HTTP_USER_AGENT'}\n";
- $body .= "Remote Host: $ENV{'REMOTE_HOST'}\n";
- $body .= "Remote Address: $ENV{'REMOTE_ADDR'}\n";
-
- &sendmail($email_alert,
- "\"regdb_updatecust\" <$email_alert>",
- "regdb_updatecust error!",
- $body);
- }
-
- sub print_html {
- my($title, $desc) = @_;
-
- print "<html>\n<body";
- &body_attributes;
- print ">\n";
-
- print <<"__EOHTML__";
- <center>
- <table border="0" cellpadding="0" cellspacing="0" width="540">
- <tr>
- <td>
- <font face="Arial, Helvetica">
- <center><h4>$title</h4></center>
- $desc
- </font>
- </td>
- </tr>
- </table>
- </center>
- </body>
- </html>
- __EOHTML__
- }
-
- sub body_attributes {
- if (param('bgcolor')) {
- print " bgcolor=\"" . param('bgcolor') . "\"";
- }
- if (param('link_color')) {
- print " link=\"" . param('link_color') . "\"";
- }
- if (param('vlink_color')) {
- print " vlink=\"" . param('vlink_color') . "\"";
- }
- if (param('alink_color')) {
- print " alink=\"" . param('alink_color') . "\"";
- }
- if (param('text_color')) {
- print " text=\"" . param('text_color') . "\"";
- }
- }
-
- sub sendmail {
- my($to, $from, $subject, $body) = @_;
-
- open (MAIL, "|$mailprog -t -oi") || return 0;
- print MAIL "To: $to\n";
- print MAIL "From: $from\n";
- print MAIL "Subject: $subject\n\n";
- print MAIL "$body\n";
- close MAIL;
- return 1;
- }